package com.rongshu.view.userInfo.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.userInfo.entity.City;
import com.rongshu.view.userInfo.iview.CityView;

import java.util.List;

import rx.Subscriber;
import rx.functions.Action0;
import rx.functions.Func1;

public class CityPresenter extends BasePresenter<CityView> {

    public CityPresenter(Context context) {
        super(context);
    }

    public void getCity(int parent_id, String sign) {
        RetorfitService.getCity(parent_id, sign)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {

                    }
                })
                .map(new Func1<City, List<City.ResponseBean>>() {
                    @Override
                    public List<City.ResponseBean> call(City city) {
                        return city.getResponse();
                    }
                })
                .subscribe(new Subscriber<List<City.ResponseBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(List<City.ResponseBean> responseBeans) {
                        if (getView() != null) {
                            getView().onGetCity(responseBeans);
                        }
                    }
                });
    }
}
